//package controller;
//
//import com.alibaba.fastjson.JSONObject;
//import com.huawei.services.runtime.Context;
//import com.huawei.services.runtime.entity.apig.APIGTriggerEvent;
//import com.huawei.services.runtime.entity.apig.APIGTriggerResponse;
//import entity.User;
//import org.hibernate.Session;
//import org.hibernate.SessionFactory;
//import org.hibernate.Transaction;
//import org.hibernate.boot.MetadataSources;
//import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
//import org.hibernate.service.ServiceRegistry;
//
//import java.io.UnsupportedEncodingException;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Map;
//
//public class TestController {
//
//
//    public APIGTriggerResponse insertUserTest(APIGTriggerEvent event, Context context) throws UnsupportedEncodingException {
//        System.out.println(event);
//        Map<String, String> headers = new HashMap<String, String>();
//        headers.put("Content-Type", "application/json");
////      Object o = JSONObject.parse(event.getRawBody());
//        //生成一个注册机对象
//        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
//        //使用注册机机对象serviceRegistry创建sessionFactory
//        SessionFactory sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
////        SessionFactory annotationFactory = new AnnotationConfiguration().configure().addAnnotatedClass(User.class).buildSessionFactory();
//        //xml
//        Session session = sessionFactory.openSession();
//        //注解
////        Session session = annotationFactory.openSession();
//        //4. 手动开启事务，（最好是手动开启事务）
//        Transaction transaction = session.beginTransaction();
//        User user2 = new User();
//        user2.setPhoneNumber("23232323");
//        user2.setUserName("hello");
//        user2.setLastPasswordResetDate(new Date());
//        session.save(user2);
////        6. 事务提交
//        transaction.commit();
////        7. 释放资源
//        session.close();
//        sessionFactory.close();
//        System.out.println(JSONObject.toJSONString(user2));
//        return new APIGTriggerResponse(200, headers, JSONObject.toJSONString(user2));
//    }
//}
